var mysql = require('mysql');
var $conf = require('../conf/db');
var $itemSqlMapping = require('./itemSqlMapping');

// 使用连接池，提升性能
var pool  = mysql.createPool( $conf.mysql);


var response =  {
	ret:0,
	msg: 'success'
}

module.exports = {
	query: function (param, callback) {
		 pool.getConnection(function(err, connection) {
			connection.query($itemSqlMapping.query(param),  function(err, result) {
				if(!err){
					response.data=result;
					callback(response);
				}else{
					console.log(err);
					response.ret=1;
					callback( response);
				}
				connection.release();
			});
		});
	}
};